package com.wwwarehouse.financialcenter.adapter.moneyhouse;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wwwarehouse.common.tools.ConvertUtils;
import com.wwwarehouse.financialcenter.R;
import com.wwwarehouse.financialcenter.bean.bindingcard.MoneyHouseInfomationBean;

import java.util.List;

/**
 * @author Joseph on 2017/9/6.
 *         <p/>
 */

public class MoneyHouseAdapter
        extends RecyclerView.Adapter<MoneyHouseAdapter.ViewHolder> {

    private Context mContext = null;
    private List<MoneyHouseInfomationBean.DataBean> mList = null;
    private int mHeight = 0;
    private OnItemClickListener mListener = null;

    public MoneyHouseAdapter(Context context, List<MoneyHouseInfomationBean.DataBean> list, int height) {
        this.mContext = context;
        this.mList = list;
        this.mHeight = height;
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mListener = listener;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(
                View.inflate(mContext, R.layout.financial_center_money_house_item, null));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) holder.rl_item.getLayoutParams();
        params.height = (mHeight - ConvertUtils.dip2px(mContext, 30)) / 3;//35等于条目间距 + RecyclerView顶部和底部边距
        holder.mName.setText(mList.get(position).getBusinessName());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener != null) {
                    mListener.ItemClickListener(position, v, mList.get(position));
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public interface OnItemClickListener {
        void ItemClickListener(int position, View view, MoneyHouseInfomationBean.DataBean data);
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        TextView mName;
        RelativeLayout rl_item ;

        ViewHolder(View itemView) {
            super(itemView);
            rl_item = (RelativeLayout) itemView.findViewById(R.id.rl_item);
            mName = (TextView) itemView.findViewById(R.id.tv_name);
        }
    }
}
